package cn.jtfadmin.activiti.service.impl;

import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ActivitiObjectNotFoundException;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.form.TaskFormHandler;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntityImpl;
import org.activiti.engine.impl.util.FormHandlerUtil;
import org.activiti.engine.impl.util.ProcessDefinitionUtil;
import org.activiti.engine.task.Task;

import java.io.Serializable;
import java.util.Map;

public class GetTaskFormCmd implements Command<TaskFormData>, Serializable {

    private static final long serialVersionUID = 1L;
    protected String processDefinitionId;
    protected String taskDefinitionKey;
    protected String taskExecutionId;
    public GetTaskFormCmd(String processDefinitionId, String taskDefinitionKey,
                          String taskExecutionId) {
        this.processDefinitionId = processDefinitionId;
        this.taskDefinitionKey = taskDefinitionKey;
        this.taskExecutionId = taskExecutionId;
    }

    public TaskFormData execute(CommandContext commandContext) {
        TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(processDefinitionId, taskDefinitionKey);
        if (taskFormHandler == null) {
            return null;
        }
        TaskEntity task = new TaskEntityImpl();
        task.setExecutionId(taskExecutionId);
        return taskFormHandler.createTaskForm(task);
    }

}
